//
//  HMSelectPeriodCell.m
//  HotelManager
//
//  Created by r on 17/4/21.
//  Copyright © 2017年 Xun. All rights reserved.
//

#import "HMSelectPeriodCell.h"

@interface HMSelectPeriodCell ()

@property (nonatomic, strong) UIView *circleView;
@property (nonatomic, strong) UILabel *dayLab;//!<日期lab
@property (nonatomic, strong) UILabel *startEndLab;//!<开始lab

@property (nonatomic, strong) UIView *line;

@end

@implementation HMSelectPeriodCell


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self initUI];
    }
    return self;
}

- (void)refreshCellWithDay:(NSInteger)day cellType:(PeriodCellType)type {
    
    if (day) {
        self.dayLab.text = @(day).stringValue;
    }
    
    if (type == PeriodCellType_Blank) {
        self.dayLab.text = @"";
        self.circleView.hidden = YES;
        self.startEndLab.hidden = YES;
        
    } else if (type == PeriodCellType_Normal) {
        
        self.dayLab.textColor = kGlobalTextColorLightGray;
        self.circleView.hidden = YES;
        self.startEndLab.hidden = YES;
        self.startEndLab.text = @"截止";

    } else if (type == PeriodCellType_Future) {
        
        self.dayLab.textColor = [UIColor blackColor];
        self.circleView.hidden  = YES;
        self.startEndLab.hidden = YES;
        
    } else if (type == PeriodCellType_Start) {
        self.dayLab.textColor = [UIColor whiteColor];
        self.circleView.hidden  = NO;
        self.startEndLab.hidden = NO;
        self.startEndLab.text = @"选中";
        
    } else if (type == PeriodCellType_End) {
        self.dayLab.textColor = [UIColor whiteColor];
        self.circleView.hidden = NO;
        self.startEndLab.hidden = NO;
        self.startEndLab.text = @"截止";
    }
}

#pragma mark - 搭建UI

- (void)initUI {
    
    [self.contentView addSubview:self.circleView];
    [self.contentView addSubview:self.dayLab];
    [self.contentView addSubview:self.startEndLab];
    [self.contentView addSubview:self.line];
    
    [self.circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(@0);
        make.size.mas_equalTo(SASizeMake(50, 50));
    }];
    
    [self.dayLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(@0);
        make.bottom.equalTo(@(kScaleNum(-20)));
    }];
    
    [self.startEndLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(@0);
        make.bottom.equalTo(self.dayLab.mas_top).with.offset(kScaleNum(-6));
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(@0);
        make.height.mas_equalTo(1);
    }];
}

#pragma mark - Getters

- (UIView *)circleView {
    if (!_circleView) {
        _circleView = [[UIView alloc] init];
        _circleView.backgroundColor = kRedColor;
        _circleView.layer.cornerRadius = kScaleNum(25);
    }
    return _circleView;
}

- (UILabel *)dayLab{
    if (!_dayLab){
        _dayLab = [[UILabel alloc] init];
        _dayLab.textColor = [UIColor blackColor];
        _dayLab.font = kFont(13);
    }
    return _dayLab;
}

- (UILabel *)startEndLab{
    if (!_startEndLab){
        _startEndLab = [[UILabel alloc] init];
        _startEndLab.textColor = [UIColor whiteColor];
        _startEndLab.font = kBFont(11);
    }
    return _startEndLab;
}

- (UIView *)line{
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

@end
